package cn.practice.chat.stream;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.stereotype.Component;

/**
 * @ClassName MessageProducer
 * @Description:
 * @Author A-TAO
 * @Date 2022/11/8
 * @Version V1.0
 **/
@Slf4j
@Component
public class MessageProducer {

    @Autowired
    private StreamBridge streamBridge;

    public void sendMessage(String topic, Object message){
        log.info("topic={}, 发送消息：{}", topic, message);
        streamBridge.send(topic, MessageBuilder.withPayload(message).build());
    }


}
